package binarytreedemo;

import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 黎鹤舞
 * Date: 2024-01-22
 * Time: 23:44
 */
public class Test {



    public static void main(String[] args) {
        BinaryTree binaryTree = new BinaryTree();
        BinaryTree.TreeNode root = binaryTree.createTree();
        //System.out.println(root.val);
        binaryTree.preOrder(root);
        System.out.println();
        binaryTree.inOrder(root);
        System.out.println();
        binaryTree.postOrder(root);
        System.out.println();
        System.out.println("层序遍历：");
        binaryTree.levelOrder(root);
        System.out.println();

        Stack<BinaryTree.TreeNode> stack = new Stack<>();
        binaryTree.getPath(root,root.left.right.right,stack);

        System.out.println("====");

        /*boolean flg = binaryTree.isCompleteTree(root);
        System.out.println(flg);
        Queue<BinaryTree.TreeNode> queue = new LinkedList<>();
        queue.offer(null);
        queue.offer(null);
        queue.offer(null);
        System.out.println(queue.size());*/
    }

    /*
    public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            TreeNode root = createTree(str);
            //中序遍历
            inorder(root);
        }
    }

    public static int i = 0;
    private static TreeNode createTree(String str) {
        TreeNode root = null;
        char ch = str.charAt(i);
        if(ch != '#') {
           root = new TreeNode(ch);
           i++;
           root.left = createTree(str);
           root.right = createTree(str);
        }else {
            i++;
        }
        return root;
    }

    private static void inorder(TreeNode  root) {
        if(root == null) {
            return;
        }
        inorder(root.left);
        System.out.print(root.val+" ");
        inorder(root.right);
    }
}
     */


    public static void main1(String[] args) {
        BinaryTree binaryTree = new BinaryTree();
        BinaryTree.TreeNode root = binaryTree.createTree();
        //System.out.println(root.val);
        binaryTree.preOrder(root);
        System.out.println();
        binaryTree.inOrder(root);
        System.out.println();
        binaryTree.postOrder(root);
        System.out.println();
        System.out.println("节点的个数：");
        System.out.println(binaryTree.size2(root));
        System.out.println("叶子节点的个数：");
        binaryTree.getLeafNodeCount(root);
        //System.out.println(binaryTree.leafSize);
        System.out.println(binaryTree.
                getLeafNodeCount2(root));
        System.out.println("第K层节点的个数：");
        System.out.println(binaryTree.getKLevelNodeCount(root,3));

        System.out.println("树的高度：");
        System.out.println(binaryTree.getHeight3(root));

        System.out.println("查找节点：");

        BinaryTree.TreeNode ret = binaryTree.find(root, 'p');

        System.out.println(ret.val);

    }
}
